<!--
 * @FilePath     : /layui/demo/1548.html
 * @Description  : 渲染不同条数据时的 性能
 * @Date         : 2025-02-24 13:48
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-02-24 13:48
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div id="demo1" class="xm-select-demo"></div>
    <button class="btn" id="demo1-test1">测试1000条</button>
    <button class="btn" id="demo1-test2">测试10000条</button>
    <button class="btn" id="demo1-test3">测试10000条+分页</button>
    <pre id="demo1-result"></pre>

    <script src="/xm-select/dist/xm-select.js"></script>
    <script>
      function run(count, paging) {
        //生成数据
        var data = []
        for (var i = 0; i < count; i++) {
          data.push({
            name: '测试数据' + i,
            value: i,
          })
        }

        //记录开始渲染时间
        var startTime = Date.now()

        var demo1 = xmSelect.render({
          el: '#demo1',
          paging,
          data,
        })

        //记录结束时间
        var endTime = Date.now()

        document.getElementById('demo1-result').innerText = `渲染耗时: ${endTime - startTime} ms`
      }

      document.getElementById('demo1-test1').onclick = function () {
        run(1000, false)
      }

      document.getElementById('demo1-test2').onclick = function () {
        run(10000, false)
      }

      document.getElementById('demo1-test3').onclick = function () {
        run(10000, true)
      }

      run(1000, false)
    </script>
  </body>
</html>
